package com.mypro.mapper;


import com.mypro.entity.Dept;
import com.mypro.entity.Emp;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author user_xdd
 * @Date 2022-05-18 17:06
 * @description 使用注解的方式来配置接口,
 * 1.@Select
 * 用来配置sql语句
 * 2.@Results
 * 3.@Result
 * <p>
 * 注解模式下配置映射基数 多对一
 * 先在第一个查询方法上配置@Results（XML中的ResultMap配置）
 * 在@Results的内部配置
 * 使用 @Result配置每个列
 * 后续方法再使用@ResultMap调用第一个方法的配置
 * @One来表示联合查询返回的是一个值
 * @return
 */
public interface EmpMapper {
    @Select("select * from emp")
    @Results(id = "EmpMap",value={
            @Result(id = true,column = "empno",property = "empno",javaType = Integer.class),
            @Result(column = "mgr",property = "manager",javaType = Integer.class),
            @Result(column = "ename",property = "ename",javaType = String.class),
            @Result(column = "deptno",property = "deptno",javaType = Integer.class),
            @Result(column = "deptno",property = "dept",javaType = Dept.class,
                    one = @One(fetchType = FetchType.EAGER,select = "com.mypro.mapper.DeptMapper.queryByPrimaryKey"))
    })
    public List<Emp> queryAll();
    //根据deptno查询Emp列表的方法
    @Select("select *from emp where deptno = #{deptno}")
   @ResultMap(value = "EmpMap")
    public List<Emp> queryByDeptno(Integer deptno);
}
